package com.stan.core.mapper;

import com.stan.core.mapper.factory.MapperFactory;
import com.stan.core.vo.AdUserClickCount;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.ArrayList;
import java.util.List;


public interface AdUserClickCountMapper {
    /**
     * 单独插入
     * @param adUserClickCount
     */
    @Insert("insert into t_ad_user_count (date,uid,aid,click_count) values " +
            "(#{date},#{uid},#{aid},#{clickCount})")
    void insert(AdUserClickCount adUserClickCount);

    /**
     * 批量插入
     * @param adUserClickCountList
     */
    @Insert("<script>insert into t_ad_user_count (date,uid,aid,click_count) values " +
            "<foreach collection='adUserClickCountList' item='item' separator=','>" +
            "(#{item.date},#{item.uid},#{item.aid},#{item.clickCount})" +
            "</foreach>" +
            "</script>")
    void insertBatch(@Param("adUserClickCountList") List<AdUserClickCount> adUserClickCountList);

    /**
     * 批量更新
     */
//    @Update("<script>" +
//            "<foreach collection='adUserClickCountList' item='item' separator=';'>" +
//            "update date=#{item.date},uid=#{item.uid},aid=#{item.aid},click_count=#{item.clickCount} " +
//            "where date=#{item.date} and uid=#{item.uid} and aid=#{item.aid}" +
//            "</foreach>" +
//            "</script>")
//    void updateBatch(@Param("adUserClickCountList") List<AdUserClickCount> adUserClickCountList);
//
//    public static void main(String[] args) {
//        List<AdUserClickCount> adUserClickCountList = new ArrayList<>();
//
//        AdUserClickCount adUserClickCount = new AdUserClickCount();
//        adUserClickCount.setDate("da");
//        adUserClickCount.setClickCount(11);
//        adUserClickCountList.add(adUserClickCount);
//        AdUserClickCount adUserClickCount2 = new AdUserClickCount();
//        adUserClickCount2.setDate("2019-05-09");
//        adUserClickCount.setUid("15");
//        adUserClickCount.setAid("32");
//        adUserClickCount.setClickCount(22);
//        adUserClickCountList.add(adUserClickCount2);
//
//        MapperFactory mapperFactory = MapperFactory.getMapperFactory();
//        mapperFactory.getMapper(AdUserClickCountMapper.class).updateBatch(adUserClickCountList);
//
//    }
}
